import {constantRoute} from '@/router'
const state ={
  roles:0,
  routes:[],
  subRouter:{},
  activeName:''
}
const mutations={
  setRoutes(state,data){
    state.routes=[].concat(data)
  },
  setSubRouters(state,data){
    state.subRouter=data
  },
  setCurrentActiveName(state,data){
    state.activeName=data
  }
}
const actions={
  /**
   * 初始化项目时根据用户权限角色生成全局路由配置
   */
  async generateRoutes({commit}){
    commit('setRoutes',constantRoute)
    return []
  },
  /**
   * 初始化项目时根据路由name设置二级路由,用于layoutLeft展示
   * @param {*当前展示的路由name} routerName 
   */
  setRouterName({commit},routerName){
    const subRouter=constantRoute.filter(item=>item.name===routerName)[0]
    commit('setSubRouters',subRouter)
  },
}
const getters={
  realRoutes: state => state.routes,
  subRouter: state => state.subRouter,
  activeName: state => state.activeName,
}
export default {
  namespaced: true,
  state,
  mutations,
  actions,
  getters
}